package cn.lystudio.rohm_time_op.controller.webApi;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.lystudio.rohm_time_op.entity.po.DailyConfirmPO;
import cn.lystudio.rohm_time_op.service.DailyConfirmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/webapi/dailyConfirm")
@Slf4j
public class DailyConfirmController {
    private DailyConfirmService dailyConfirmService;
    @Autowired
    @Lazy
    public void setDailyConfirmService(DailyConfirmService dailyConfirmService) {
        this.dailyConfirmService = dailyConfirmService;
    }
    @PostMapping("/addDailyConfirm")
    @SaCheckRole(value = {"1", "11"}, mode = SaMode.OR)
    public SaResult addDailyConfirm(@RequestBody DailyConfirmPO dailyConfirm){
        String loginId = StpUtil.getLoginIdAsString();
        dailyConfirm.setUserCode(loginId);
        dailyConfirm.setConfirmDT(DateUtil.date());

        Integer res = dailyConfirmService.addDailyConfirm(dailyConfirm);
        if(res<1) {
            return SaResult.error("数据保存失败");
        }
        return SaResult.ok();
    }

    @GetMapping("/getDailyConfirm")
    public SaResult getDailyConfirm(String machineNo, String recordTimeDT){
        DailyConfirmPO dailyConfirmPO = new DailyConfirmPO();
        dailyConfirmPO.setMachineNo(machineNo);
        dailyConfirmPO.setRecordTimeDT(DateUtil.parse(recordTimeDT));
        return SaResult.data(dailyConfirmService.getDailyConfirm(dailyConfirmPO));
    };
}
